﻿<Window x:Class="Tum.PDE.ToolFramework.Modeling.Visualization.VMXExtensions.Html.View.SelectHyperlinkPopup"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:mtree="clr-namespace:Tum.PDE.ToolFramework.Modeling.Visualization.Controls.ModelTree;assembly=Tum.PDE.ToolFramework.Modeling.Visualization"
        xmlns:commands="clr-namespace:Tum.PDE.ToolFramework.Modeling.Visualization.Commands;assembly=Tum.PDE.ToolFramework.Modeling.Visualization"

        xmlns:attached="clr-namespace:Tum.PDE.ToolFramework.Modeling.Visualization.Controls.Attached;assembly=Tum.PDE.ToolFramework.Modeling.Visualization"
        xmlns:viewAttached="clr-namespace:Tum.PDE.ToolFramework.Modeling.Visualization.ViewModel.Attached;assembly=Tum.PDE.ToolFramework.Modeling.Visualization"
        
        xmlns:beh="clr-namespace:Tum.PDE.ToolFramework.Modeling.Visualization.Behaviors;assembly=Tum.PDE.ToolFramework.Modeling.Visualization"
        xmlns:inter="clr-namespace:System.Windows.Interactivity;assembly=System.Windows.Interactivity"
        
        Icon="/Tum.PDE.ToolFramework.Modeling.Visualization.VMXExtensions;component/Resources/Images/HtmlEditor/Hyperlink.ico"
        
        Width="500" Height="600" WindowStartupLocation="CenterScreen" WindowStyle="ToolWindow"
        Title="{Binding Path=Title}">
    <Window.Resources>
        <ResourceDictionary>

            <commands:CommandReference x:Key="SearchCommand" Command="{Binding Path=SelectElementSearchViewModel.SearchCommand}" />

            <DataTemplate x:Key="FoundElementsTemplate">
                <StackPanel Orientation="Vertical" Margin="0,5,0,5">
                    <StackPanel x:Name="GroupPanel" Orientation="Horizontal" Margin="0,2,0,2">
                        <TextBlock x:Name="HeaderName" Visibility="Collapsed" Margin="2,0,0,0" Text="{Binding Path=DomainElementName}" FontWeight="Bold" />
                        <TextBlock x:Name="HeaderOpenType" Visibility="Collapsed" Text=" ("/>
                        <TextBlock x:Name="HeaderType" Margin="2,0,0,0" Text="{Binding Path=DomainElementType}" FontWeight="Bold" TextOptions.TextFormattingMode="Display"/>
                        <TextBlock x:Name="HeaderCloseType" Visibility="Collapsed" Text=")"/>
                        <TextBlock x:Name="HeaderParentOpenType" Margin="2,0,0,0" Text="[" Visibility="Collapsed"/>
                        <TextBlock x:Name="HeaderParent" Text="{Binding Path=DomainElementParentFirstExistingName}" Visibility="Collapsed"/>
                        <TextBlock x:Name="HeaderParentCloseType" Text="]" Visibility="Collapsed"/>
                    </StackPanel>
                    <TextBlock x:Name="HeaderParentFullPath" Margin="0,3,0,0" Text="{Binding Path=DomainElementParentFullPath}" 
                               Visibility="Collapsed" TextTrimming="WordEllipsis" />
                </StackPanel>
                <DataTemplate.Triggers>
                    <!-- Show name if element has one-->
                    <DataTrigger Value="True" Binding="{Binding DomainElementHasName}">
                        <Setter Property="Visibility" TargetName="HeaderName" Value="Visible"/>
                        <Setter Property="Visibility" TargetName="HeaderOpenType" Value="Visible"/>
                        <Setter Property="Visibility" TargetName="HeaderCloseType" Value="Visible"/>
                        <Setter Property="Margin" TargetName="HeaderType" Value="0,0,0,0"/>
                        <Setter Property="FontWeight" TargetName="HeaderType" Value="Normal"/>
                    </DataTrigger>

                    <DataTrigger Value="True" Binding="{Binding DomainElementHasParentFullPath}">
                        <Setter Property="Visibility" TargetName="HeaderParentFullPath" Value="Visible"/>
                    </DataTrigger>

                    <DataTrigger Value="True" Binding="{Binding DomainElementParentHasFirstExistingName}">
                        <Setter Property="Visibility" TargetName="HeaderParent" Value="Visible"/>
                        <Setter Property="Visibility" TargetName="HeaderParentOpenType" Value="Visible"/>
                        <Setter Property="Visibility" TargetName="HeaderParentCloseType" Value="Visible"/>
                    </DataTrigger>
                </DataTemplate.Triggers>
            </DataTemplate>
        </ResourceDictionary>
    </Window.Resources>
    <Grid>
        <Grid.RowDefinitions>
            <RowDefinition Height="*" />
            <RowDefinition Height="Auto" />
        </Grid.RowDefinitions>
        <TabControl x:Name="TabControl" MinHeight="300" Margin="3, 3, 3, 3" Grid.Row="0">
            <TabItem x:Name="TabItemSearch" Header="Search" viewAttached:ViewModelAttachedCommands.Activated="{Binding Path=SelectElementSearchViewModel.ActivatedCommand}">
                <Grid>
                    <Grid.RowDefinitions>
                        <RowDefinition Height="30"/>
                        <RowDefinition Height="*"/>
                    </Grid.RowDefinitions>

                    <TextBox x:Name="TextBoxSearch" Text="{Binding Path=SelectElementSearchViewModel.SearchText, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" Margin="3,3,3,3" Grid.Row="0">
                        <TextBox.InputBindings>
                            <KeyBinding Command="{StaticResource SearchCommand}" Key="Enter" />
                        </TextBox.InputBindings>
                    </TextBox>

                    <Canvas HorizontalAlignment="Right" Grid.Row="0">
                        <Image Width="16" Height="16" Margin="-27, 6, 0, 0" Source="/Tum.PDE.ToolFramework.Images;component/Views/Search-16.png">
                            <Image.InputBindings>
                                <MouseBinding MouseAction="LeftClick" Command="{StaticResource SearchCommand}" />
                            </Image.InputBindings>
                        </Image>
                    </Canvas>
                    <ListBox x:Name="ListBoxResults" Margin="3,0,3,3" Grid.Row="1" ItemsSource="{Binding Path=SelectElementSearchViewModel.SearchResultViewModels, Mode=OneWay}"
                             attached:ListBoxHelper.DoubleClickDialogResult="True"
                             ItemTemplate="{StaticResource FoundElementsTemplate}"
                             SelectedItem="{Binding Path=SelectElementSearchViewModel.SearchSelectedElement, Mode=TwoWay}"/>
                </Grid>
            </TabItem>
            <TabItem x:Name="TabItemModelTree" Header="Model Tree" viewAttached:ViewModelAttachedCommands.Activated="{Binding Path=SelectElementTreeViewModel.ActivatedCommand}">
                <mtree:ModelTreeView x:Name="ModelTree" ItemsSource="{Binding Path=SelectElementTreeViewModel.ModelTreeRootViewModels, Mode=OneTime}">
                    <inter:Interaction.Behaviors>
                        <beh:TreeViewSelectedItemBehavior SelectedItem="{Binding Mode=TwoWay, Path=SelectElementTreeViewModel.ModelTreeSelectedElement}"/>
                    </inter:Interaction.Behaviors>
                </mtree:ModelTreeView>
            </TabItem>
            <TabItem x:Name="TabItemWebHyperlink" Header="WWW-Hyperlink" viewAttached:ViewModelAttachedCommands.Activated="{Binding Path=SelectWebHyperlinkViewModel.ActivatedCommand}">
                <Grid>
                    <Grid.RowDefinitions>
                        <RowDefinition Height="Auto"/>
                        <RowDefinition Height="Auto"/>
                        <RowDefinition Height="*"/>
                    </Grid.RowDefinitions>
                    <TextBlock Grid.Row="0" Text="Web hyperlink:"/>
                    <TextBox Grid.Row="1" Text="{Binding Path=SelectWebHyperlinkViewModel.HyperlinkText, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"/>
                </Grid>
            </TabItem>
        </TabControl>

        <StackPanel Orientation="Horizontal" HorizontalAlignment="Right" Grid.Row="1" Margin="3,8,3,5">
            <Button x:Name="ButtonAdd" IsDefault="True"  Content="Ok" Width="70" Margin="0, 0, 3, 0" IsEnabled="{Binding Path=IsSelectionValid}" attached:ButtonHelper.DialogResult="True" />
            <Button x:Name="ButtonCancel" Content="Cancel" Width="70" IsCancel="True"/>
        </StackPanel>
    </Grid>
</Window>
